module.exports = function ($scope, $resource, $modalInstance, toaster, travel, getDate, flag) {

    $scope.group = travel;
    $scope.flag = flag;
    $scope.sale = {};
    var url = '';
    
    if(flag){
        $scope.sale.guide_mobile = travel.guide_mobile;
        $scope.sale.guide_name = travel.guide_name;
        $scope.sale.price = travel.price / 100;
        $scope.sale.address = travel.address;
        $scope.sale.sale_code = travel.sale_code;
        $scope.travel_time = {'lable': travel.travel_time, 'opened': false};
        url = '/api/as/goc/outboundtravel/updateOutboundSale';
    } else {
        $scope.travel_time = {'lable': getDate(new Date()), 'opened': false};
        url = '/api/ac/goc/outboundTravelService/addOutboundSale';
    }


    $scope.ok = function(){
        if(!$scope.sale.guide_name){
            toaster.warning({title: '', body: '请填写导游姓名'});
            return;
        }
        if(!$scope.sale.guide_mobile){
            toaster.warning({title: '', body: '请填写导游手机'});
            return;
        }
        if(!$scope.sale.address){
            toaster.warning({title: '', body: '请填写集合地点'});
            return;
        }
        if(!$scope.sale.price || $scope.sale.price < 0){
            toaster.warning({title: '', body: '请填写正确的价格'});
            return;
        }
        $scope.sale.travel_time = getDate($scope.travel_time.lable);
        $scope.sale.group_code = travel.group_code;

        $resource(url, {}, {}).save($scope.sale, function(res){
            if (res.errcode === 0) {
                toaster.success({title: '', body: '添加成功'});
                $modalInstance.close($scope.sale);
            } else {
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }

    $scope.close = function () {
        $modalInstance.dismiss('cancel');
    }

    //打开日历空间,选择时间
	$scope.dateOpen = function ($event, item) {
        if(flag){
            return;
        }
		$event.preventDefault();
		$event.stopPropagation();
		item.opened = true;
	};


};